package com.itgungnir.designpattern.composite;

import java.util.ArrayList;
import java.util.List;

public class MyFile {
	private String name; // 文件名称
	private boolean isDir; // 是否是文件夹，是返回true，否则返回false
	private double size; // 文件大小
	private int level; // 文件所在的层级，根文件是0级
	private List<MyFile> subFiles; // 文件的子文件（只有文件夹才有子文件）

	public MyFile() {
		subFiles = new ArrayList<>();
	}

	public MyFile(String name, boolean isDir, double size, int level) {
		this();
		this.name = name;
		this.isDir = isDir;
		this.size = size;
		this.level = level;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isDir() {
		return isDir;
	}

	public void setDir(boolean isDir) {
		this.isDir = isDir;
	}

	public double getSize() {
		return size;
	}

	public void setSize(double size) {
		this.size = size;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public List<MyFile> getSubFiles() {
		return subFiles;
	}

	public void setSubFiles(List<MyFile> subFiles) {
		this.subFiles = subFiles;
	}

	public void addSubFile(MyFile file) {
		this.subFiles.add(file);
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		for (int i = 1; i <= level; i++) {
			sb.append("----");
		}
		sb.append("(" + (isDir() ? "dir" : "file") + ")");
		sb.append(getName());
		sb.append("(" + getSize() + "K)");
		return sb.toString();
	}
}